<template>
  <div class="box">
    <h2>子组件 add----{{$store.state.count}}</h2>
    从vuex中获取的值:<label>{{$store.state.count}}</label>
    <br />
    <button @click="add" >值+1</button>
    <button @click="asyncAdd">延时+1</button>
    <button @click="$store.dispatch('asyncCounts',100)">延时+100</button>
    <button @click="asyncCounts(10000)">延时+10000</button>
  </div>
</template>

<script>
import {mapActions} from 'vuex'
export default {
  name: 'AddItem',
  methods:{
    ...mapActions(['asyncCounts']),
  add(){
    this.$store.commit('addCount')
  },
  asyncAdd(){
     this.$store.dispatch('asyncCount')
  }
  }
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>